package com.c1.client.dialog.r;

import lombok.Setter;

import javax.swing.*;
import java.awt.*;

@Setter
public class RPanel extends JPanel {
    private JScrollPane fatherJScrollPane;

    private Image dkImage;
    private Image fsImage;

    private int dkImageWidth;
    private int dkImageHeight;
    private int fsImageWidth;
    private int fsImageHeight;

    public void setImage(Image fsImage, Image dkImage) {
        this.fsImage = fsImage;
        this.dkImage = dkImage;
        fsImageWidth = fsImage.getWidth(null);
        fsImageHeight = fsImage.getHeight(null);
        dkImageWidth = dkImage.getWidth(null);
        dkImageHeight = dkImage.getHeight(null);
    }

    @Override
    protected void paintComponent(Graphics g) {
        setPreferredSize(printV2(g));
        revalidate();
        fatherJScrollPane.updateUI();
    }

    public Dimension printV2(Graphics g) {
        if (fsImage != null) {
            g.drawImage(fsImage, 0, 0, null);
        }
        if (dkImage != null) {
            g.drawImage(dkImage, 0, fsImageHeight, null);
        }
        return new Dimension(Math.max(dkImageWidth, fsImageWidth), dkImageHeight + fsImageHeight);
    }
}
